import itertools
from framework.eventsource import EventSource
from framework.event import Event
from framework import scrapeutils

def get_events():
    return SneakyPetes().get_events()

class SneakyPetes(EventSource):
    def get_events(self):
        gigs_url = 'http://www.sneakypetes.co.uk/gigs/'
        markup = scrapeutils.http_get(gigs_url)
        html = scrapeutils.build_tree(markup)
        eventnodes = html.cssselect('.vevent')
        return map(_extract_event, eventnodes)

def _extract_event(eventnode):
    return Event(
        title=eventnode.cssselect('.summary')[0].text_content(),
        start_datetime=eventnode.cssselect('.dtstart')[0].text_content(),
        description=eventnode.cssselect('.description')[0].text_content()
    )
